package com.nextpro.media.file;

import javax.swing.filechooser.FileFilter;
import java.io.File;

/**
 * Created by Administrator on 14-2-18.
 */
public class MediaFileFilter extends FileFilter {
    private final String[]supportType = {"flv","avi","asx","asf","mpg","wmv","3gp","mp4","mov","hlv"};
    @Override
    public boolean accept(File f) {
        String fileName = f.getName();
        return f.isDirectory() || endWithOneOf(fileName);
    }
    public boolean endWithOneOf(String fileName){
        for (String support:supportType){
            if (fileName.endsWith(support)){
                return true;
            }
        }
        return false;
    }
    @Override
    public String getDescription() {
        StringBuilder stringBuilder = new StringBuilder();
        for (String support:supportType){
            stringBuilder.append(support);
            stringBuilder.append(",");
        }
        stringBuilder.deleteCharAt(stringBuilder.length()-1);

        return stringBuilder.toString();
    }
}
